-module(device_sup).

-behaviour(supervisor).

%% API
-export([start_link/0, start_child/1,start_child/2, start_child/3]).

%% Supervisor callbacks
-export([init/1]).

%% Helper macro for declaring children of supervisor
-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
-define(MAX_WAIT, 16#ffffffff).

%% ===================================================================
%% API functions
%% ===================================================================

start_link() ->
    supervisor:start_link({local, ?MODULE}, ?MODULE, []).

%% ===================================================================
%% Supervisor callbacks
%% ===================================================================

init([]) ->
    {ok, { {one_for_one, 3, 10}, []} }.


start_child(Mod) -> start_child(Mod, []).

start_child(Mod, Args) -> start_child(Mod, Mod, Args).

start_child(ChildId, Mod, Args) ->
    supervisor:start_child(
        ?MODULE,
        {ChildId, {Mod, start_link, Args},
        transient, ?MAX_WAIT, worker, [Mod]}).
